/** <a href="http://www.cpupk.com/decompiler">Eclipse Class Decompiler</a> plugin, Copyright (c) 2017 Chen Chao. **/
package com.minierp.validator;

import com.minierp.dao.TallySetDao;
import com.minierp.model.TallySet;
import java.util.List;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

public class TallySetValidator implements Validator {
	private TallySetDao tallySetDao;

	public TallySetDao getTallySetDao() {
		return this.tallySetDao;
	}

	public void setTallySetDao(TallySetDao tallySetDao) {
		this.tallySetDao = tallySetDao;
	}

	public boolean supports(Class clazz) {
		return TallySet.class.isAssignableFrom(clazz);
	}

	public void validate(Object obj, Errors errors) {
		TallySet form = (TallySet) obj;
		if (form.getTitle() != null && !form.getTitle().trim().equals("")) {
			List list = this.tallySetDao.getList(form.getTitle(), form.getId());
			if (list.size() > 0) {
				errors.rejectValue("title", "", "『帐套名称』已经存在，请重新输入");
			}
		} else {
			errors.rejectValue("title", "", "请输入『帐套名称』");
		}

	}
}